/* stylelint-disable at-rule-no-unknown,at-rule-empty-line-before */
@import "../../../style/default";

$input-affix-width: 19px;

// size mixins for input
@mixin input-lg() {
  padding: $input-padding-vertical-lg $input-padding-horizontal-lg;
  height: $input-height-lg;
  font-size: $font-size-lg;
}

@mixin input-sm() {
  padding: $input-padding-vertical-sm $input-padding-horizontal-sm;
  height: $input-height-sm;
}

// input status
// == when focus or actived
@mixin active($color: $outline-color) {
  border-color: darken($color, 5%);
  outline: 0;
  box-shadow: 0 0 $outline-blur-size $outline-width rgba($color, 0.2);
}

// == when hoverd
@mixin hover($color: $input-hover-border-color) {
  border-color: darken($color, 5%);
}

@mixin disabled() {
  background-color: $input-disabled-bg;
  opacity: 1;
  cursor: not-allowed;
  color: $input-disabled-color;
  border-color: $input-border-color;
  &:hover {
    @include hover($input-border-color);
  }
}

@mixin border() {
  @if($input-border-type) {
    border-top: $input-border-top;
    border-bottom: $input-border-bottom;
    border-left: $input-border-left;
    border-right: $input-border-right;
  }@else{
    border: $input-border-base;
  }
}

// Basic style for input
@mixin input() {
  position: relative;
  display: inline-block;
  padding: $input-padding-vertical-base $input-padding-horizontal-base;
  width: 100%;
  height: $input-height-base;
  font-size: $font-size-base;
  line-height: $input-line-height;
  color: $input-color;
  background-color: $input-bg;
  //background-image: none;
  //border: $input-border-width $input-border-style $input-border-color;
  @include border;
  border-radius: $input-border-radius;
  @include placeholder(); // Reset placeholder
  transition: all .3s;

  &:hover {
    @include hover();
  }

  &:focus {
    @include active();
  }

  &-disabled {
    @include disabled();
  }

  // Reset height for `textarea`s
  //textarea.#{$style-prefix}-input {
  //  max-width: 100%; // prevent textearea resize from coming out of its container
  //  height: auto;
  //  vertical-align: bottom;
  //  transition: all .3s, height 0s;
  //  min-height: $input-height-base;
  //  margin: 6px 0 10px;
  //}

  // Size
  &-lg {
    @include input-lg();
  }

  &-sm {
    @include input-sm();
  }
}

// label input
@mixin input-group($inputClass) {
  position: relative;
  display: table;
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;

  // Undo padding and float of grid classes
  &[class*="col-"] {
    float: none;
    padding-left: 0;
    padding-right: 0;
  }

  > [class*="col-"] {
    padding-right: 8px;
    &:last-child {
      padding-right: 0;
    }
  }

  &-addon,
  &-wrap,
  > .#{$inputClass} {
    display: table-cell;

    &:not(:first-child):not(:last-child) {
      border-radius: 0;
    }
  }

  &-addon,
  &-wrap {
    width: 1px; // To make addon/wrap as small as possible
    white-space: nowrap;
    vertical-align: middle;
  }

  &-wrap > * {
    display: block !important;
  }

  .#{$inputClass} {
    float: left;
    width: 100%;
    margin-bottom: 0;
    &:focus {
      z-index: 1; // Fix https://gw.alipayobjects.com/zos/rmsportal/DHNpoqfMXSfrSnlZvhsJ.png
    }
  }

  &-addon {
    padding: 0 $input-padding-horizontal-base;
    font-size: $font-size-base;
    font-weight: normal;
    line-height: 1;
    color: $input-color;
    text-align: center;
    background-color: $input-addon-bg;
    border: $input-border-width $input-border-style $input-border-color;
    border-radius: $input-border-radius;
    position: relative;
    transition: all .3s;

    // Reset Select's style in addon
    .#{$style-prefix}-select {
      margin: -($input-padding-vertical-base + 1px) (-$input-padding-horizontal-base); // lesshint spaceAroundOperator: false

      .#{$style-prefix}-select-selection {
        background-color: inherit;
        margin: -1px;
        border: $input-border-width $input-border-style transparent;
        box-shadow: none;
      }

      &-open,
      &-focused {
        .#{$style-prefix}-select-selection {
          color: $primary-color;
        }
      }
    }

    // Expand addon icon click area
    // https://github.com/apes-design/apes-design/issues/3714
    > i:only-child:after {
      position: absolute;
      content: '';
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
    }
  }

  // Reset rounded corners
  > .#{$inputClass}:first-child,
  &-addon:first-child {
    border-bottom-right-radius: 0;
    border-top-right-radius: 0;

    // Reset Select's style in addon
    .#{$style-prefix}-select .#{$style-prefix}-select-selection {
      border-bottom-right-radius: 0;
      border-top-right-radius: 0;
    }
  }

  > .#{$inputClass}-affix-wrapper {
    &:not(:first-child) .#{$inputClass} {
      border-bottom-left-radius: 0;
      border-top-left-radius: 0;
    }

    &:not(:last-child) .#{$inputClass} {
      border-bottom-right-radius: 0;
      border-top-right-radius: 0;
    }
  }

  &-addon:first-child {
    border-right: 0;
  }
  &-addon:last-child {
    border-left: 0;
  }

  > .#{$inputClass}:last-child,
  &-addon:last-child {
    border-bottom-left-radius: 0;
    border-top-left-radius: 0;

    // Reset Select's style in addon
    .#{$style-prefix}-select .#{$style-prefix}-select-selection {
      border-bottom-left-radius: 0;
      border-top-left-radius: 0;
    }
  }

  // Sizing options
  &-lg .#{$inputClass},
  &-lg > &-addon {
    @include input-lg();
  }

  &-sm .#{$inputClass},
  &-sm > &-addon {
    @include input-sm();
  }

  // Fix https://github.com/apes-design/apes-design/issues/5754
  &-lg .#{$style-prefix}-select-selection--single {
    height: $input-height-lg;
  }

  &-sm .#{$style-prefix}-select-selection--single {
    height: $input-height-sm;
  }

  .#{$inputClass}-affix-wrapper {
    display: table-cell;
    width: 100%;
    float: left;
  }

  &-compact {
    display: block;
    @include clearfix;

    & > * {
      border-radius: 0;
      border-right-width: 0;
      vertical-align: top; // https://github.com/apes-design/apes-design-pro/issues/139
      float: none;
      display: inline-block;
    }

    // Undo float for .apes-input-group .apes-input
    .#{$inputClass} {
      float: none;
      z-index: auto;
    }

    // reset border for Select, DatePicker, AutoComplete, Cascader, Mention, TimePicker
    & > .#{$style-prefix}-select > .#{$style-prefix}-select-selection,
    & > .#{$style-prefix}-calendar-picker .#{$style-prefix}-input,
    & > .#{$style-prefix}-select-auto-complete .#{$style-prefix}-input,
    & > .#{$style-prefix}-cascader-picker .#{$style-prefix}-input,
    & > .#{$style-prefix}-mention-wrapper .#{$style-prefix}-mention-editor,
    & > .#{$style-prefix}-time-picker .#{$style-prefix}-time-picker-input {
      border-radius: 0;
      border-right-width: 0;
    }

    & > *:first-child,
    & > .#{$style-prefix}-select:first-child > .#{$style-prefix}-select-selection,
    & > .#{$style-prefix}-calendar-picker:first-child .#{$style-prefix}-input,
    & > .#{$style-prefix}-select-auto-complete:first-child .#{$style-prefix}-input,
    & > .#{$style-prefix}-cascader-picker:first-child .#{$style-prefix}-input,
    & > .#{$style-prefix}-mention-wrapper:first-child .#{$style-prefix}-mention-editor,
    & > .#{$style-prefix}-time-picker:first-child .#{$style-prefix}-time-picker-input {
      border-top-left-radius: $input-border-radius;
      border-bottom-left-radius: $input-border-radius;
    }

    & > *:last-child,
    & > .#{$style-prefix}-select:last-child > .#{$style-prefix}-select-selection,
    & > .#{$style-prefix}-calendar-picker:last-child .#{$style-prefix}-input,
    & > .#{$style-prefix}-select-auto-complete:last-child .#{$style-prefix}-input,
    & > .#{$style-prefix}-cascader-picker:last-child .#{$style-prefix}-input,
    & > .#{$style-prefix}-mention-wrapper:last-child .#{$style-prefix}-mention-editor,
    & > .#{$style-prefix}-time-picker:last-child .#{$style-prefix}-time-picker-input {
      border-top-right-radius: $input-border-radius;
      border-bottom-right-radius: $input-border-radius;
      border-right-width: 1px;
    }
  }
}

@mixin input-affix-wrapper($inputClass) {
  position: relative;
  display: inline-block;
  width: 100%;

  .#{$inputClass} {
    z-index: 1;
  }

  &:hover .#{$inputClass}:not(.#{$inputClass}-disabled) {
    @include hover();
  }

  .#{$inputClass}-prefix,
  .#{$inputClass}-suffix {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 2;
    line-height: 0;
    color: $input-color;
    :not(.anticon) {
      line-height: $input-line-height;
    }
  }

  .#{$inputClass}-prefix {
    left: $input-padding-horizontal-base + 1px;
  }

  .#{$inputClass}-suffix {
    right: $input-padding-horizontal-base + 1px;
  }

  .#{$inputClass}:not(:first-child) {
    padding-left: $input-padding-horizontal-base + $input-affix-width;
  }

  .#{$inputClass}:not(:last-child) {
    padding-right: $input-padding-horizontal-base + $input-affix-width;
  }
}
